import { reqDeleteLayer, reqGetLayer, reqUpdateLayer, reqUploadLayer } from "@/api/layer";
import { requestGetData, requestIsSuccess } from "@/api/request";
import { MapCoordSys } from "./myMapOpt";

export class Layer {
    id: number
    url: string
    name: string
    coordsys: MapCoordSys
    layer:any
    constructor({ id, url, name, coordsys,layer}: {
        id: number
        url: string
        name: string
        coordsys: MapCoordSys
        layer:any
    }) {
        this.id = id
        this.url = url
        this.name = name
        this.coordsys = coordsys || MapCoordSys.CJ02
        this.layer = layer
    }
    upload() {
        return reqUploadLayer(this)
    }
    update() {
        return reqUpdateLayer(this)
    }
    delete() {
        return reqDeleteLayer(this.id.toString())
    }
    static async getLayer() {
        let result = await reqGetLayer()
        let layerList: Layer[] =[]
        result.data.forEach(item => {
            layerList.push(new Layer(item))
        })
        return layerList
    }
}